//
//  RHEfficiencyRankItemCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/11/1.
//

#import "RHEfficiencyRankItemCell.h"
@interface RHEfficiencyRankItemCell()

@property (nonatomic, strong) QMUILabel *titleLab;

@property (nonatomic, strong) QMUILabel *contentLab;

@property (nonatomic, strong) UIProgressView *progressView;
@end
@implementation RHEfficiencyRankItemCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}
- (void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    self.titleLab.text = dic[@"productTypeCode"];
    self.contentLab.text = [NSString stringWithFormat:@"%ld%%",[dic[@"value"] integerValue]];
    [self.progressView setProgress:[dic[@"value"] integerValue]/100.0 animated:YES];
}

-(void)setColor:(NSString *)color
{
    self.progressView.progressTintColor = kCOLOR_HEX(color);
}

-(void)setupUI
{
    kWeakSelf;
    UIView *bgView = kView;
    bgView.backgroundColor = CFTabViewBgColor;
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(5, 10, 5, 10));
    }];
  
    _icon = [[UIImageView alloc]init];
    [bgView addSubview:_icon];
    [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(24);
        make.left.mas_offset(10);
        make.centerY.mas_offset(0);
    }];
        
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.textColor = [UIColor colorWithHexString:@"#171A1D" alpha:1];
    titleLab.textAlignment = NSTextAlignmentLeft;
    titleLab.font = kSYSTEMFONT(14);
    [bgView addSubview:titleLab];
    self.titleLab = titleLab;
  
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_offset(0);
        make.left.equalTo(weakSelf.icon.mas_right).offset(5);
    }];
    
    CGFloat value = arc4random_uniform(100)/100.0;
    QMUILabel *contentLab = [[QMUILabel alloc]init];
    contentLab.text = [NSString stringWithFormat:@"%zd%%",(NSInteger)(value*100)];
    contentLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:1];
    contentLab.textAlignment = NSTextAlignmentRight;
    contentLab.font = kSYSTEMFONT(14);
    [bgView addSubview:contentLab];
    self.contentLab = contentLab;
    [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgView.mas_centerY).offset(-3);
        make.right.mas_offset(-15);
    }];
    
    UIProgressView *progress = [[UIProgressView alloc]init];
//    progress.progress = value;
    progress.progressTintColor = kCOLOR_HEX(@"67E787");
    progress.trackTintColor = kCOLOR_HEX(@"E7E7E7");
    progress.layer.cornerRadius = 2.5;
    progress.layer.masksToBounds = YES;
    [bgView addSubview:progress];
    self.progressView = progress;
    [progress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(60);
        make.right.equalTo(contentLab);
        make.height.offset(5);
        make.top.equalTo(bgView.mas_centerY).offset(3);
    }];
        
   
    
    
}
@end
